package design;

public class Singleton {

    private String name = "singleton";

    private static volatile Singleton singleton;
    private Singleton(){}

    public static Singleton getInstance(){
        if (null == singleton){
            synchronized (Singleton.class){
                if (null == singleton){
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }

    public static void main(String[] args) {

        create();

    }
    public static void create(){
        Singleton singleton = Singleton.getInstance();
        System.out.println(singleton.name);
        System.out.println(singleton);
        singleton = Singleton.getInstance();
        System.out.println(singleton);
    }
}
